{extend name="public:layout" /}
{block name="title"}{$moudleName}列表{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <ol class="breadcrumb">
                    <li class="active"><i class="fa fa-hand-o-right"></i> {$moudleName}列表</li>
                </ol>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left">
                    <button type="button" onclick="CheckAll();" class="btn btn-white">全</button>
                    <button type="button" onclick="CheckOther();" class="btn btn-white">反</button>
                    <a class="btn btn-primary"
                       href="{:url('add',['mid'=>$Request.param.mid,'cid'=>$Request.param.cid])}">
                        <i class="fa fa-plus"></i>&nbsp;添加{$moudleName}
                    </a>
                </div>
                <div class="pull-right">
                    <form class="form-inline" id="searchForm" method="post">
                        <div class="form-group">
                            <div class="input-group">
                                <input class="form-control" type="text" placeholder="请输入检索关键词"
                                       name="title" value="{$query.title}"/>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-info">
                            <i class="fa fa-search"></i> 搜索
                        </button>
                        <a class="btn btn-white" href="{:url('index',['mid'=>$Request.param.mid])}">
                            <i class="fa fa-trash"></i> 清空
                        </a>
                    </form>
                </div>
                <div class="clearfix"></div>
            </div>
            <style>
                #grid .tag{margin-right:15px;color:#989898;}
                #grid .tag b{font-weight:500;color:#333;}

            </style>
            {volist name="list" id="vo"}
            <table class="table table-bordered" id="grid" style="margin-bottom:10px;">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th width="80">客户头像</th>
                    <th width="100">录入人</th>
                    <th width="100">负责人</th>
                    <th width="80">客户状态</th>
                    <th width="80">客户来源</th>
                    <th>客户名称</th>
                    <th>联系电话</th>
                    <th width="60">性别</th>
                    <th width="300">地址</th>
                    <th width="60">居住</th>
                    <th>家庭成员</th>
                    <th width="70">排序</th>
                    <th width="100">关联操作</th>
                </tr>
                </thead>
                <tbody>

                <tr>
                    <td rowspan="4">
                        <input name="aid[]" type="checkbox" class="checkbox" value="{$vo.aid}" />
                    </td>
                    <td rowspan="4">
                        <img src="{$vo.head_img}" alt="" style="width:80px;">
                    </td>
                    <td>{:get_field_value('user','username',['uid'=>$vo.uid])}</td>
                    <td>{:get_field_value('user','username',['uid'=>$vo.owner_id])}</td>
                    <td>{:get_field_value('dict','dict_name',['dict_id'=>$vo.customer_type])}</td>
                    <td>{$vo.source}</td>
                    <td>{$vo.title}</td>
                    <td>{$vo.mobile}</td>
                    <td>{$vo.sex_text}</td>
                    <td>{$vo.address}</td>
                    <td>{$vo.live_num}</td>
                    <td>{$vo.family}</td>
                    <td> <input type="text" class="form-control input-sm batchSort" value="{$vo.sort}"
                                name="sort[{$vo.aid}]" /></td>
                    <td rowspan="4">
                        <a href="{:url('add',['mid'=>4,'customer_id'=>$vo['aid']])}" class="btn btn-primary btn-xs btn-block">添加新工单</a>
                        <a href="{:url('add',['customer_id'=>$vo['aid'],'mid'=>8])}" class="btn btn-warning btn-xs btn-block">添加常用联系人</a>
                        <a href="{:url('edit',['aid'=>$vo['aid'],'mid'=>$vo['mid']])}" class="btn btn-success btn-xs btn-block">编辑信息</a>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('del')}" data-params="aid={$vo.aid}&mid={$vo.mid}" class="btn btn-warning btn-xs btn-block">删除</a>
                    </td>
                </tr>
                <tr>
                    <td>其他信息</td>
                    <td colspan="10">
                        {notempty name="vo.qq"}<span class="tag">QQ：<b>{$vo.qq}</b></span>{/notempty}
                        {notempty name="vo.email"}<span class="tag">邮箱：<b>{$vo.email}</b></span>{/notempty}
                        {notempty name="vo.customer_job"}<span class="tag">职业：<b>{$vo.customer_job}</b></span>{/notempty}
                        {notempty name="vo.age"}<span class="tag">年龄段：<b>{$vo.age}</b></span>{/notempty}
                        {notempty name="vo.consume"}<span class="tag">消费能力：<b>{$vo.consume}</b></span>{/notempty}
                    </td>
                </tr>
                <tr>
                    <td>常用联系人</td>
                    <td colspan="10" class="contact_box" data-aid="{$vo.aid}" id="contact{$vo.aid}">
                    </td>
                </tr>
                <tr>
                    <td>工单信息</td>
                    <td colspan="10" class="order_box" data-aid="{$vo.aid}" id="order{$vo.aid}">
                    </td>
                </tr>
                </tbody>
            </table>
            {/volist}
            <div class="p8">
                <div class="pull-left">
                    <div class="form-inline">
                        <button type="button" onclick="upOrder();" class="btn btn-info">
                            <i class="fa fa-sort"></i> 排序
                        </button>
                        <button type="button" onclick="batchDel(CheckboxValue())" class="btn btn-danger">
                            <i class="fa fa-trash"></i> 删除
                        </button>
                    </div>
                </div>
                <div class="page-bar">{$list->render()}</div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="contact_tpl">
    {{ if data=='' }}
    还没有添加常用联系人
    {{ else }}
    <table class="table table-striped">
        <thead>
        <tr>
            <th>姓名</th>
            <th>联系方式</th>
            <th>性别</th>
            <th>与客户关系</th>
            <th>备注</th>
            <th width="100">操作</th>
        </tr>
        </thead>
        <tbody>
        {{ each data as value }}
        <tr>
            <td>{{ value.title}}</td>
            <td>{{ value.telphone }}</td>
            <td>{{ value.sex_text}}</td>
            <td>{{ value.nexus}}</td>
            <td>{{ value.remarks}}</td>
            <td>
                <a href="{:url('edit',['mid'=>8])}&aid={{ value.aid }}" class="btn btn-success btn-xs">编辑</a>
                <a href="javascript:;" onclick="doAction(this);"
                   data-msg="确认删除吗？" data-url="{:url('del')}" data-params="aid={{ value.aid }}&mid={{ value.mid }}" class="btn btn-warning btn-xs">删除</a>
            </td>
        </tr>
        {{ /each }}
        </tbody>
    </table>
    {{ /if }}
</script>
<script type="text/html" id="order_tpl">
{{ if data=='' }}
客户还没有添加工单，请新增工单并开始进行跟进
{{ else }}
<table class="table table-striped">
    <thead>
    <tr>
        <th>工单地址</th>
        <th>总负责人</th>
        <th>跟进负责人</th>
        <th>设计负责人</th>
        <th>安装负责人</th>
        <th>工单进度</th>
        <th>工单状态</th>
        <th width="100">操作</th>
    </tr>
    </thead>
    <tbody>
    {{ each data as value }}
    <tr>
        <td>{{ value.title}}</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>
            <a href="{:url('edit')}?mid={{ value.mid }}&aid={{ value.aid }}" class="btn btn-success btn-xs">编辑</a>
            <a href="javascript:;" onclick="doAction(this);"
               data-msg="确认删除吗？" data-url="{:url('del')}" data-params="aid={{ value.aid }}&mid={{ value.mid }}" class="btn btn-warning btn-xs">删除</a>
        </td>
    </tr>
    {{ /each }}
    </tbody>
</table>
{{ /if }}
</script>
<script type="text/javascript">
    $(function () {
        $('.contact_box').each(function () {
            var aid=$(this).data('aid');
            getContact(aid);
        })
        $('.order_box').each(function () {
            var aid=$(this).data('aid');
            getOrder(aid);
        })
    })
    //批量删除文章
    function batchDel(aid) {
        if (IsMore(aid)) {
            var url = "{:url('del')}";
            var params = {'aid': aid, 'mid': "{$Request.param.mid}"};
            doConfirm('你确认要删除吗？', url, params, function (data) {
                if (data.code == 1) {
                    rePage();
                }
            });
        }
    }
    //更新排序
    function upOrder() {
        if ($(".batchSort").length == 0) {
            alert('您还没有添加内容！');
            return false;
        }
        var params = $(".batchSort").serialize();
        var url = "{:url('upOrder',['mid'=>$Request.param.mid])}";
        getAjax(url, params, function (data) {
            if (data.code == 1) {
                rePage();
            }
        });
    }
    /*获取常用联系人*/
    function getContact(customer_id) {
        var url="{:url('logic.customer_contact/getlist')}"
        $.post(url,{customer_id:customer_id},function (res) {
            In('templete',function () {
                var html=template('contact_tpl',{data:res});
                $('#contact'+customer_id).empty().html(html);
            })
        })
    }
    /*获取工单信息*/
    function getOrder(customer_id){
        var url="{:url('logic.customer_order/getlist')}"
        $.post(url,{customer_id:customer_id},function (res) {
            console.log(res);
            In('templete',function () {
                var html=template('order_tpl',{data:res});
                $('#order'+customer_id).empty().html(html);
            })
        })
    }
</script>
{/block}